import { useEffect } from 'react';
import { Routes, Route, useLocation } from "react-router-dom";
import Home from "@/pages/Home";
import DigitalPayment from "@/pages/DigitalPayment";
import PaymentCollection from "@/pages/PaymentCollection";
import CrossBorderPayment from "@/pages/CrossBorderPayment";
import ForeignCardService from "@/pages/ForeignCardService";
import VerticalIndustry from "@/pages/VerticalIndustry";
import RetailStore from "@/pages/RetailStore";
import SmallBank from "@/pages/SmallBank";
import RegularReports from "@/pages/RegularReports";
import InvestorActivities from "@/pages/InvestorActivities";
import NewsUpdates from "@/pages/NewsUpdates";
import CompanyNews from "@/pages/CompanyNews";
import MediaReport from "@/pages/MediaReport";
import MediaLibrary from "@/pages/MediaLibrary";
import AboutIntroduction from "@/pages/AboutIntroduction";
import AboutCulture from "@/pages/AboutCulture";
import AboutPartners from "@/pages/AboutPartners";
import AboutContact from "@/pages/AboutContact";
import NotFound from "@/pages/NotFound";
import { useState } from "react";
import { AuthContext } from '@/contexts/authContext';

export default function App() {
  const location = useLocation();
  const [isAuthenticated, setIsAuthenticated] = useState(false);

  // 页面加载或路由变化时滚动到顶部
  useEffect(() => {
    window.scrollTo(0, 0);
  }, [location.pathname]);

  const logout = () => {
    setIsAuthenticated(false);
  };

  return (
    <AuthContext.Provider
      value={{ isAuthenticated, setIsAuthenticated, logout }}
    >
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/digital-payment" element={<DigitalPayment />} />
        <Route path="/payment-collection" element={<PaymentCollection />} />
        <Route path="/cross-border-payment" element={<CrossBorderPayment />} />
        <Route path="/foreign-card-service" element={<ForeignCardService />} />
        <Route path="/solutions/vertical-industry" element={<VerticalIndustry />} />
        <Route path="/solutions/retail-store" element={<RetailStore />} />
        {/* Investor Relations Routes */}

        <Route path="/investor-relations/regular-reports" element={<RegularReports />} />
        <Route path="/investor-relations/activities" element={<InvestorActivities />} />
        <Route path="/investor-relations/news" element={<NewsUpdates />} />
        <Route path="/solutions/small-bank" element={<SmallBank />} />
           {/* 新闻中心子路由 */}
           <Route path="/news-center/company" element={<CompanyNews />} />
           <Route path="/news-center/media" element={<MediaReport />} />
           <Route path="/news-center/resources" element={<MediaLibrary />} />
          <Route path="/about/introduction" element={<AboutIntroduction />} />
          <Route path="/about/culture" element={<AboutCulture />} />
          <Route path="/about/partners" element={<AboutPartners />} />
          <Route path="/about/contact" element={<AboutContact />} />
          <Route path="/404" element={<NotFound />} />
          <Route path="*" element={<NotFound />} />
      </Routes>
    </AuthContext.Provider>
  );
}
